package tests{
	import asunit.errors.AssertionFailedError;
	import asunit.framework.TestCase;
	
	import com.asnike.P.bejeweled.*;
	
	import flash.events.*;
	
	public class TestGameControl extends TestCase{
		public function TestGameControl(testMethod:String=null){
			super(testMethod);
		}
		
		private var _gameControl:GameControl;
		private var _gameModel:GameModel;
		private var _gameView:GameView;
		
		private var _testMap:Array = [[2,2,2,1,2,3],
			[0,2,3,5,4,1],
			[3,3,1,3,5,1],
			[0,2,1,1,3,2],
			[1,4,4,5,2,1],
			[2,3,4,5,4,2]];
		
		override protected function setUp():void{
			_gameModel = new GameModel;
			_gameView = new GameView;
			_gameControl = new GameControl( _gameModel, _gameView );
			_gameControl.setJewelSize( 6, 6 );
			_gameControl.gameReady();
		}
		
		public function testSetView():void{
			
			assertEquals( _gameView, _gameControl.getViewAtTest() );
			try{
				_gameControl = new GameControl( _gameModel, null );
			}catch( $e:TypeError ){
				assertTrue( true );
			}
		}
		
		public function testSetJewelSize():void{
			assertEqualsArrays( [6, 6], _gameControl.getJewelSizeAtTest() );
			
			try{
				_gameControl.setJewelSize( -1, 0 );
				fail( 'error!!!' );
			}catch( $e:RangeError ){
				assertTrue( true );
			}
		}
		public function testGenerateMap():void{
			assertEquals( 36, _gameControl.getMapLengthAtTest() );
		}
		
		public function testSelectJewel():void{
			var jewel0:Jewel, jewel1:Jewel;
			
			jewel0 = _gameControl.getJewelAtTest( 1, 1 );
			_gameControl.setSelectJewelAtTest( jewel0 );
			assertEquals( jewel0, _gameControl.getSelectJewelsAtTest()[0] );
		}
		
		public function testSelectedJewelNearJewel():void{
			var jewel0:Jewel, jewel1:Jewel;
			
			jewel0 = _gameControl.getJewelAtTest( 2, 2 );
			jewel1 = _gameControl.getJewelAtTest( 2, 3 );
			_gameControl.setSelectJewelAtTest( jewel0 );
			assertTrue( _gameControl.isNearJewelAtTest( jewel1 ) );
			
			jewel1 = _gameControl.getJewelAtTest( 2, 3 );
		}
	}
}